#pragma once
#ifndef GAME_APP_H
#define GAME_APP_H

#include "gamecomponent.h"
#include "Player.h"
#include "Level.h"
#include "Camera.h"
#include "terrain.h"

enum unit_type{
				FACTORY = 0,
				TANK};

class GameApp :	public GameComponent
{
private:
	
	GameComponent* player_one;

	Camera* gc;

	AlphaMatrixStack* model_view;
	AlphaMatrix* projection;

	GLuint program;
	GLuint fbo;
	GLuint fbo_tex;
	GLuint fbo_depth;

	GLuint rbo;
	GLuint vao;	
	GLuint vbo;
	GLuint fbo_ID_tex;

	GLint mouse_x;
	GLint mouse_y;

	GLuint ov_tex_1;
	GLuint ov_tex_2;
	GLuint ov_tex_3;
	GLuint ov_tex_4;

	int button_hovered;

	bool b_h;

	bool r_move;

	GameComponent* current_unit;

	float current_identifier;
	float *test;

	terrain *t;

	int current_unit_type;

public:
	GameApp(void);
	GameApp::GameApp(char* fname);
	~GameApp(void);

	inline void update()
	{
		updateMe(this);
		updateChildren(this);
	}

	void initMe(GameComponent* g);
	inline void init()
	{

		this->initMe(this);
		this->initChildren(this);
	}

	void keyBoardHandler(SDL_Event e);

	void render();

	void reshapeWindow(SDL_Event e)
	{
		if(e.type == SDL_WINDOWEVENT)
		{
			if(e.window.event == SDL_WINDOWEVENT_RESIZED)
			{
				glViewport(0,0, e.window.data1, e.window.data2);
				projection->loadPerspective(AlphaMath::DegToRadians(35.0f), (float)(e.window.data1) / (float)(e.window.data2), 0.1f, 1000.0f);
			}
		}
	}

	void initTexBuffer();

	void captureMouse(SDL_Event e);
};

#endif